//
//  RecommendHotContentView.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/26.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "RecommendHotContentView.h"
#import "RecommendHotCollectionViewCell.h"

#define leftMargin (WIDTH - 2 * jisuan(20) - jisuan(220) * 3) / 2.0

static NSString *goodsContentRecommendHotCellID = @"contentView";

@interface RecommendHotContentView () <UICollectionViewDelegate, UICollectionViewDataSource>

@property (strong, nonatomic) UICollectionView *goodsCollectionView;

@end

@implementation RecommendHotContentView

- (instancetype)init {
    
    if (self = [super init]) {
        
        [self addSubview:self.goodsCollectionView];
    
    }
    
    return self;

}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    [self.goodsCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left);
        make.right.mas_equalTo(weakSelf.mas_right);
        make.top.mas_equalTo(weakSelf.mas_top);
        make.bottom.mas_equalTo(weakSelf.mas_bottom);
    }];
    
}

#pragma mark -delegate \ datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    RecommendHotCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:goodsContentRecommendHotCellID forIndexPath:indexPath];
    
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"进货推荐，热销排行cell点击");
    
}

#pragma mark -lazy

- (UICollectionView *)goodsCollectionView {
    
    if (!_goodsCollectionView) {
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(jisuan(220), jisuan(362));
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        flowLayout.minimumLineSpacing = jisuan(20);
        flowLayout.minimumInteritemSpacing = jisuan(20);
        
        flowLayout.sectionInset = UIEdgeInsetsMake(jisuan(44), leftMargin, jisuan(44), leftMargin);
        
        _goodsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _goodsCollectionView.backgroundColor = WhiteColor;
        
        _goodsCollectionView.bounces = NO;
        
        _goodsCollectionView.delegate = self;
        _goodsCollectionView.dataSource = self;
        
        _goodsCollectionView.showsVerticalScrollIndicator = NO;
        _goodsCollectionView.showsHorizontalScrollIndicator = NO;
        
        [_goodsCollectionView registerClass:[RecommendHotCollectionViewCell class] forCellWithReuseIdentifier:goodsContentRecommendHotCellID];
        
        if (@available(iOS 11.0, *)) {
            
            _goodsCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
        }
        
    }
    
    return _goodsCollectionView;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
